package demo3;


public class Computer {
    public void powerOn(){
        System.out.println("打开笔记本电脑");
    }

    public void powerOff(){
        System.out.println("关闭笔记本电脑");
    }
    public void useDevice(IUsb iUsb){//往里面存进接口
        iUsb.openDevice();
        if(iUsb instanceof Mouse){
            Mouse mouse = (Mouse) iUsb;
            //iUsb.click();//如果直接这么做是不对的，click是Mouse类中特有的方法，所以需要强制转化
            mouse.click();
        }else if (iUsb instanceof KeyBoard){
            KeyBoard keyBoard = (KeyBoard) iUsb;
            keyBoard.inPut();
        }
        iUsb.closeDevice();
    }
}
